package com.atgm.mall.gmmailproduct.controller;

import com.atgm.common.utils.PageUtils;
import com.atgm.common.utils.R;
import com.atgm.mall.gmmailproduct.entity.GameGoodsEntity;
import com.atgm.mall.gmmailproduct.service.GameGoodsService;
import com.atgm.mall.gmmailproduct.vo.req.GameGoodsReqVo;
import com.atgm.mall.gmmailproduct.vo.resp.GameGoodsDetailVo;
import com.atgm.mall.gmmailproduct.vo.resp.GamePriceRespVo;
import com.atgm.mall.gmmailproduct.vo.resp.OrderGameRespVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 游戏商品
 */
@RestController
@RequestMapping("gmmallproduct/goods")
public class GameGoodsController {

    @Autowired
    private GameGoodsService gameService;

    @GetMapping("/info")
    public R getGoodsInfo(@RequestParam("ids") List<Long> goodsIds) {
        List<GameGoodsEntity> list = gameService.getGoodsInfoByIds(goodsIds);
        return R.ok().setData(list);
    }

    @GetMapping("/list")
    public R getGoodsList(@RequestParam Map<String, Object> params) {
        PageUtils page = gameService.getGoodsInfo(params);
        return R.ok().setData(page);
    }

    /**
     * 条件获取
     * @param params
     * @return
     */
    @GetMapping("/condlist")
    public R getGoodsListByCond(@RequestParam Map<String, Object> params) {
        PageUtils page = gameService.queryGoodsInfoByCond(params);
        return R.ok().setData(page);
    }

    @GetMapping("/orderGameInfo")
    public R getOrderGameInfo(@RequestParam("gameIds") List<Long> gameIds) {
        List<OrderGameRespVo> list = gameService.queryOrderGameInfo(gameIds);
        return R.ok().setData(list);
    }

    /**
     * 获取游戏名称信息
     * @return
     */
    @GetMapping("/getGameNameOfInput")
    public R getGameNameOfInput(@Param("name") String name){
        List<String> list = gameService.queryGameName(name);
        return R.ok().setData(list);
    }

    /**
     * 获取单个游戏的详细信息
     * @param id
     * @return
     */
    @GetMapping("/info/{id}")
    public R getGameInfoById(@PathVariable("id") Long id) {
        GameGoodsDetailVo gameGoodsDetailVo = gameService.queryGoodsInfoBYId(id);
        return R.ok().setData(gameGoodsDetailVo);
    }

    /**
     * 获取游戏简单信息
     * @param id
     * @return
     */
    @GetMapping("/simpleInfo/{id}")
    public R getGameSimpleInfoById(@PathVariable("id") Long id) {
        GameGoodsEntity gameGoodsEntity = gameService.querySimpleInfoById(id);
        return R.ok().setData(gameGoodsEntity);
    }

    /**
     * 添加游戏
     * @param gameGoodsReqVo
     * @return
     */
    @PostMapping("/save")
    public R saveGameGoods(@RequestBody GameGoodsReqVo gameGoodsReqVo) {
        String gameId = gameService.saveGameGoodsInfo(gameGoodsReqVo);
        return R.ok().setData(gameId);
    }

    /**
     * 获取下架状态中游戏
     * @param params
     * @return
     */
    @GetMapping("/offshelf")
    public R getOffShelfGame(@RequestParam Map<String, Object> params) {
        PageUtils page = gameService.queryOffShelfGames(params);
        return R.ok().setData(page);
    }

    /**
     * 上、下架游戏
     * @param gameGoodsReqVo
     * @return
     */
    @PutMapping("/editGameShelf")
    public R editGameShelf(@RequestBody GameGoodsReqVo gameGoodsReqVo) {
        gameService.updateGameShelf(gameGoodsReqVo);
        return R.ok();
    }

    /**
     * 获取游戏商品的价格信息
     * @param gameIds
     * @return
     */
    @GetMapping("/getGamePrice")
    public R getGamePrice(@RequestParam("ids") List<Long> gameIds) {
        List<GamePriceRespVo> list = gameService.queryGamePrice(gameIds);
        return R.ok().setData(list);
    }

}
